package com.yserp.api.baseapi;

import java.util.ArrayList;
import java.util.List;

import cn.basecode.server.common.constants.DictConst;
import cn.basecode.server.common.vo.BaseUserBean;
import cn.basecode.server.common.vo.TreeVo;

import com.google.common.collect.Lists;

public class BSystemUserBean extends BaseUserBean {
	
    private String fingerPrint;

    private String faceRecognition;
    
	
	//排序
	private String sort;
	
	public String getSort() {
		return sort;
	}

	public void setSort(String sort) {
		this.sort = sort;
	}

	
	
	public String getFingerPrint() {
		return fingerPrint;
	}

	public void setFingerPrint(String fingerPrint) {
		this.fingerPrint = fingerPrint;
	}

	public String getFaceRecognition() {
		return faceRecognition;
	}

	public void setFaceRecognition(String faceRecognition) {
		this.faceRecognition = faceRecognition;
	}

	public BSystemUserBean(String userName,String userId){
		this.setUserName(userName);
		this.setUserId(userId);
		BSysUserOrgBean userOrg=new BSysUserOrgBean();
		TSysOrganizationBean orgInf=new TSysOrganizationBean();
		userOrg.setOrgId("1");
		orgInf.setOrgId("1");
		orgInf.setOrgCode("34");
		userOrg.setOrgInfo(orgInf);
		this.setUserDeptInfo(userOrg);
	}
	public BSystemUserBean(){}
	private static final long serialVersionUID = 1L;
	private List<BSysRoleBean> roleList = new ArrayList<BSysRoleBean>();
	private List<TSysMenuBean> menuList = new ArrayList<TSysMenuBean>();
	private BSysUserOrgBean userDeptInfo=null;
	public List<BSysRoleBean> getRoleList() {
		return roleList;
	}
	public  List<String> getActAuthList(){
		List<String> fowParam=Lists.newArrayList();
		List<String> rList=getRoleListNames();
		String minDeptCode=getUserDeptCode();
		String pDeprCode=DictConst.getPreDeptCodeByOrgId(getUserDeptId());
		String readorgCode=DictConst.getUserDataReadAuthOrgCode(getUserDeptId());
		String preorgCode=DictConst.getPreOrgCodeByOrgId(getUserDeptId());
		fowParam.add("ACT_VARS_USER_"+getUserId());
		fowParam.add("ACT_VARS_DEPT_"+getUserDeptCode());
		for(String _name:rList){
			fowParam.add("ACT_VARS_ROLE_"+_name);
			//部门内
			if(minDeptCode!=null)fowParam.add("ACT_VARS_DR_Z_"+minDeptCode+"_"+_name);
			// 机构内
			if(readorgCode!=null)fowParam.add("ACT_VARS_DR_B_"+readorgCode+"_"+_name);
			//上级机构  当前人所属机构为提交的上级机构
			if(readorgCode!=null)fowParam.add("ACT_VARS_DR_SJJ_"+readorgCode+"_"+_name);
			// 下级机构 当前人所属机构的上级机构为提交人机构
			if(preorgCode!=null)fowParam.add("ACT_VARS_DR_XJJ_"+preorgCode+"_"+_name);
			
			// 上级部门
			if(minDeptCode!=null)fowParam.add("ACT_VARS_DR_SJB_"+minDeptCode+"_"+_name);
			// 下级部门
			if(pDeprCode!=null)fowParam.add("ACT_VARS_DR_XJB_"+pDeprCode+"_"+_name);
		}
		return fowParam;
	}
	public TreeVo getOrgInfo() {
		return orgInfo;
	}

	public void setOrgInfo(TreeVo orgInfo) {
		this.orgInfo = orgInfo;
	}

	public void setUserDeptInfo(BSysUserOrgBean userDeptInfo) {
		this.userDeptInfo = userDeptInfo;
	}

	public List<String> getRoleListIds(){
		List<String>  list=new ArrayList<String>();
		if(roleList.size()>0&&roleList.get(0) instanceof BSysRoleBean){
			for( BSysRoleBean bean:roleList){
				list.add(bean.getRoleId()) ;
			}
		}
		return list;
	}
	public List<String> getRoleListNames(){
		List<String>  list=new ArrayList<String>();
		if(roleList.size()>0&&roleList.get(0) instanceof BSysRoleBean){
			for( BSysRoleBean bean:roleList){
				list.add(bean.getRoleName()) ;
			}
		}
		return list;
	}
	public  boolean isContainRoleId(String roleId){
		return getRoleListIds().contains(roleId);
	}
	public void setRoleList(List<BSysRoleBean> roleList) {
		this.roleList = roleList;
	}
	@Override
	 public String toString() {
		 return getUserName();
	 }

	public List<TSysMenuBean> getMenuList() {
		return menuList;
	}

	public void setMenuList(List<TSysMenuBean> menuList) {
		this.menuList = menuList;
	}


	@Override
	public String getUserDeptName() {
		TSysOrganizationBean info=getUserDeptInfo();
		if(info!=null){
			return info.getOrgName();
		}
		return null;
	}
	@Override
	public String getUserDeptFullName() {
		TSysOrganizationBean info=getUserDeptInfo();
		if(info!=null){
			return info.getOrgNameFull();
		}
		return null;
	}
	@Override
	public String getUserDeptId() {
		TSysOrganizationBean info=getUserDeptInfo();
		if(info!=null){
			return info.getOrgId();
		}
		return null;
	}
	public  String getUserDeptType(){
		TSysOrganizationBean info=getUserDeptInfo();
		if(info!=null){
			return info.getOrgType();
		}
		return null;
	}
	
	//获取orgType,0省级及直属，1,市及市直属，2,区县及区县直属，4派出所
	private String getOrgLev(){
		String orgType=getUserDeptType();
		return orgType.substring(0, 1);
	}
	public String authorityCode(){
		String orgLev=getOrgLev();
		String orgCode=getUserDeptCode();
		if("0".equals(orgLev)){
			return "";
		}else if("1".equals(orgLev)){
			if("00".equals(orgCode.subSequence(2, 4))){
				return orgCode.substring(0, 6);
			}else {
				return orgCode.substring(0, 4);
			}
		}else if("2".equals(orgLev)) {
			return orgCode.substring(0, 6);
		}else {
			return orgCode;
		}
	}
	
	public  String getUserDeptCode(){
		TSysOrganizationBean info=getUserDeptInfo();
		if(info!=null){
			return info.getOrgCode();
		}
		return null;
	}
	

	@SuppressWarnings("unchecked")
	@Override
	public <T> T getUserDeptInfo() {
		TSysOrganizationBean info=null;
		if(userDeptInfo!=null){
			info=userDeptInfo.getOrgInfo();
		}
		return (T)info;
	}
	@SuppressWarnings("unchecked")
	private TreeVo orgInfo;
	@Override
	public <T>T getUserPostInfo() {
		TSysPostBean info=null;
		if(userDeptInfo!=null){
			info=userDeptInfo.getPostInfo();
		}
		return (T)info;
	}

	@Override
	public TreeVo getUserOrgTreeVo() {
		return orgInfo;
	}

	@Override
	public String getUserOrgId() {
		if(orgInfo==null){
			return null;
		}
		return orgInfo.getId();
	}

	@Override
	public String getUserOrgName() {
		if(orgInfo==null){
			return null;
		}
		return orgInfo.getName();
	}

	@Override
	public String getUserOrgCode() {
		if(orgInfo==null){
			return null;
		}
		return orgInfo.getCode();
	}

	private String openId;

	public String getOpenId() {
		return openId;
	}

	public void setOpenId(String openId) {
		this.openId = openId;
	}
	
	private String supplierId;
	private Integer isSupplier;

	public String getSupplierId() {
		return supplierId;
	}

	public void setSupplierId(String supplierId) {
		this.supplierId = supplierId;
	}

	public Integer getIsSupplier() {
		return isSupplier;
	}

	public void setIsSupplier(Integer isSupplier) {
		this.isSupplier = isSupplier;
	}

}
